{
  LW Timer -- LightWave Timer

  Timers can be used to execute code at specified intervals.
  This interface provides a means of creating one or more
  interval-based timer instances.

  Based on lwtimer.h which is:
  Copyright 2008, NewTek, Inc.
}

{
  Copyright 2012, Jameel Halabi

  This unit is part of the BlaiseWave wrapper,
  which is licensed under the BSD 2-Clause license (see licenses/license.txt).
}
unit LW_Timer;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils;

const
  LWTIMER_GLOBAL = 'LW Timer' ;

type
  { Signature for the timer event function.  The function takes a pointer
    to the data provided when the timer was added (see timerAdd()), and
    returns a Boolean 1 or 0 to indicate whether or not this particular
    timer should be removed from the internal timer list.  If a timer
    implicitly removes itself by returning 1, a subsequent call to
    timerRemove() is not needed for this instance. }
  TTimerEventProc = function
                    (       Data : Pointer ) : Integer ;

  PLWTimer = ^TLWTimer ;
  TLWTimer = record
    { proc - callback function for timer expiration
      data - user-defined data pointer
      interval - timeout value expressed in milliseconds }
    TimerAdd      : procedure
                    (        TimerEvProc : TTimerEventProc ;
			     Data        : Pointer         ;
			     Interval    : UInt64          ) ;

    { Timers can be explicitly removed by calling the following function and
      specifying the 'proc' callback as well as an optional interval.
      If interval is 0, then the first instance of a timer with 'proc' as its
      callback will be removed.
      If interval is >0, then only the 'proc' instance with that interval
      will be removed.

      Unless the timer instance implicitly removes itself by returning 1 from
      its callback function, each call to timerAdd() MUST HAVE a corresponding
      call to  timerRemove(),  Otherwise you run the risk of leaving a dangling
      function pointer within Layout, which can (and probably will) eventually
      lead to a crash of the application.

      proc     - callback function for timer expiration (same used for timerAdd())
      interval - timeout value expressed in milliseconds (same used for timerAdd()) }
      TimerRemove : procedure
                    (        TimerEvProc : TTimerEventProc ;
			     Interval    : UInt64          ) ;
  end;

implementation

end.

